package com.loop;

import java.util.Random;
       //调取随机数作为密码输入，设a为密码错误次数，在循环2次后，求a的平均值。
public class RandomDemo7 {
    public static void main(String[] args) {
        int okPassword = 3; int count = 0;
        for (int j = 1; j <= 2; j++) {
            for (int i = 1; i <= 10 ; i++) {
                Random r = new Random();

                int data = r.nextInt(10);

                System.out.println(data);

                if (data == okPassword){
                    System.out.println("The password is correct");
                    break;
                }else {
                    System.out.println("password error");
                    count++;
                }
            }
        }
        double average = count * 1.0 / 2;
        System.out.println(average);
        }
    }

